<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />

  <link rel=stylesheet href='arwing.css' type='text/css' />
  <!-- *** Replace the key below below with your own API key, available at http://code.google.com/apis/maps/signup.html *** -->
  <script src="http://www.google.com/jsapi?key=ABQIAAAAwbkbZLyhsmTCWXbTcjbgbRSzHs7K5SvaUdm8ua-Xxy_-2dYwMxQMhnagaawTo7L1FE1-amhuQxIlXw"></script>
  <script type="text/javascript" src="http://earth-api-samples.googlecode.com/svn/trunk/lib/math3d.js"></script>
  <script type="text/javascript" src="http://earth-api-samples.googlecode.com/svn/trunk/lib/keyboard-focus-hack.js"></script>
  <script type="text/javascript" src="http://earth-api-samples.googlecode.com/svn/trunk/lib/kmldomwalk.js"></script>
  <script type="text/javascript" src="arwing.js"></script>
  <script type="text/javascript" src="http://gogo-cow-shooter.googlecode.com/files/soundmanager2.js"></script>
  <script type="text/javascript">
google.load("earth", "1");
google.load("maps", "2");

var ge = null;
var geocoder;
var arwing;
var soundManager;
var planet;

function el(e) { return document.getElementById(e); }

function Sample(description, url) {
  this.description = description;
  this.url = url;
  return this;
}

var samples = [];

function init() {
  geocoder = new GClientGeocoder();
  planet = "earth";
  google.earth.createInstance("map3d", initCallback, failureCallback);
}

function initCallback(object) {
  ge = object;
  ge.getWindow().setVisibility(true);
  ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
  ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
  
  arwing = new Arwing();
  keyboardFocusHack(ge);
}

function marsCallback(object){
	ge = object;
	ge.getWindow().setVisibility(true);
	ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
	
	arwing = new Arwing();
	keyboardFocusHack(ge);
}

function failureCallback(err) {
   alert("Failure to load Google Earth");
}

function submitLocation() {
  doGeocode(el('address').value);
}

function doGeocode(address) {
  geocoder.getLatLng(address, function(point) {
    if (point) {
      if (ge != null && arwing != null) {
        arwing.teleportTo(point.y, point.x);
      }
    }
  });
}

function showMars(){
	//delete Earth
	document.getElementById('map3d').innerHTML = '';
	//create Mars
	planet = "mars";
	google.earth.createInstance('map3d', marsCallback, failureCallback, { database: 'http://khmdb.google.com/?db=mars' });
}

function showEarth(){
	//delete Mars
	document.getElementById('map3d').innerHTML = '';
	//create Earth
	planet = "earth";
	google.earth.createInstance("map3d", initCallback, failureCallback);
}

  </script>
</head>
<body onload='init()' onunload="GUnload()" onKeyDown="return keyDown(event);" onKeyUp="return keyUp(event);">
<center>
  

  <div id='map3d'></div>

  <table>
    <tr>
      <td>
	To drive: use the buttons, or keyboard arrows (with focus on page).

	<div>
	  <form name='searchform' id='searchform' action='javascript:submitLocation();void(0);'>
	    <input type=text size=60 id='address' value='(enter a location to go there)'></input>
	    <input type=submit value='Teleport!'>
	  </form>

      </td>
      <td>
        <table>
	  <tr>
	    <td></td>
	    <td><input type=button class="button medw" onmousedown="gasButtonDown=true;" onmouseup="gasButtonDown = false;" value="gas"></td>
	    <td></td>
	  </tr>
	  <tr>
	    <td><input type=button class="button medw" onmousedown="leftButtonDown=true;" onmouseup="leftButtonDown=false;" value="left"></td>
	    <td></td>
	    <td><input type=button class="button medw" onmousedown="rightButtonDown=true;" onmouseup="rightButtonDown=false;" value="right"></td>
	  </tr>
	  <tr>
	    <td></td>
	    <td><input type=button class="button medw" onmousedown="reverseButtonDown=true;" onmouseup="reverseButtonDown=false;" value="reverse"></td>
	    <td></td>
	  </tr>
	</table>
      </td>
    </tr>
  </table>
</center>
</body>
</html>
